package com.zwxu.stack;

import java.util.Stack;

public class ImplementQueueByTwoStacksDemo {

	public static void main(String[] args) {


	}

}
class MyQueue {
    private Stack<Integer> stack1;
	private Stack<Integer> stack2;
	
    public MyQueue() {
		// do initialization if necessary
		stack1 = new Stack<Integer>();
		stack2 = new Stack<Integer>();
	}

	public void push(int element) {
		// write your code here
		stack1.push(element);

	}

	public int pop() {
        if(!stack2.empty()){
            return stack2.pop();
        }else{
            while(stack1.size() > 1){
                stack2.push(stack1.pop());
            }
            return stack1.pop();
        }
    }

    public int top() {
        if(!stack2.empty()){
            return stack2.peek();
        }else{
            while(!stack1.empty()){
                stack2.push(stack1.pop());
            }
            return stack2.peek();
        }
    }
}
